package com.alipay.sofa.demo.db.common.tool;

import com.alipay.sofa.demo.db.common.entity.StudentInfo;

import java.util.UUID;

/**
 * 数据制造模拟类
 * @Author Zhang Da
 * @Date 2020/2/14 20:46
 * @Version 1.0
 */
public class DataMockUtil {
    private static final String[] COLLEGES = {"计算机学院", "经济学院", "自动化学院", "外语学院"};
    private static final String[] MAJORS = {"计算机科学与技术", "工商管理", "市场营销", "贸易经济", "英语"};

    public DataMockUtil(){
        throw new IllegalStateException("Utility class");
    }

    /**
     * 模拟一个学生的数据
     * @return
     */
    public static StudentInfo mockOneStudent(){
        StudentInfo studentInfo = new StudentInfo();
        studentInfo.setStudentNo(UUID.randomUUID().toString());
        studentInfo.setSex(getDistanceRandomNum(0,1) == 0? "男": "女");
        studentInfo.setAdmissionTicketNo(randomAdmissionTicketNo());
        studentInfo.setBreachPrinciple("");
        studentInfo.setMissExam("");
        studentInfo.setCollegeName(COLLEGES[getDistanceRandomNum(0, 3)]);
        studentInfo.setClassName(studentInfo.getStudentNo().substring(0, 7));
        studentInfo.setMajorName(MAJORS[getDistanceRandomNum(0, 3)]);
        studentInfo.setScoreHearing(Double.valueOf(getDistanceRandomNum(80, 150)));
        studentInfo.setScoreReading(Double.valueOf(getDistanceRandomNum(80, 150)));
        studentInfo.setScoreWriting(Double.valueOf(getDistanceRandomNum(80, 150)));
        studentInfo.setScoreIntegratedTesting(Double.valueOf(getDistanceRandomNum(20, 80)));
        studentInfo.setScoreTotal(studentInfo.getScoreHearing()
                                    + studentInfo.getScoreReading()
                                    + studentInfo.getScoreWriting()
                                    + studentInfo.getScoreIntegratedTesting());
        studentInfo.setSchoolSystem(getDistanceRandomNum(2, 4));

        return studentInfo;
    }

    /**
     * 随机生成学生学号
     * @return
     */
    private static String randomStudentNo(){
        String year = getDistanceRandomNum(0, 9999) + "";
        String randomNumbers = getDistanceRandomNum(0, 100000000) + "";
        return  year + randomNumbers;
    }

    /**
     * 随机生成准考证号
     * @return
     */
    private static String randomAdmissionTicketNo(){
        String str1 = getDistanceRandomNum(1, 100000000) + "";
        String str2 = getDistanceRandomNum(1, 100000000) + "";
        return  str1 + str2;
    }

    /**
     * 根据起止数生成随机数
     * @param start
     * @param end
     * @return
     */
    public static int getDistanceRandomNum(int start,int end) {
        return (int)(Math.random()*(end-start+1)+start);
    }



}
